﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Acoris.Markdown
{
    /// <summary>
    /// 表示Aml内容键值对
    /// </summary>
    internal sealed class AMLValuePair:IEqualityComparer<AMLValuePair>
    {
        private string m_name;
        private string m_value;

        public AMLValuePair(string name,string value)
        {
            m_name = name;
            m_value = value;
        }

        /// <summary>
        /// 返回当前Aml内容键值对的名称
        /// </summary>
        public string Name {
            get { return m_name; }
        }

        /// <summary>
        /// 返回当前Aml内容键值对的值
        /// </summary>
        public string Value {
            get { return m_value; }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public bool Equals(AMLValuePair x, AMLValuePair y)
        {
            return x.Equals(y);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public int GetHashCode(AMLValuePair obj)
        {
            return obj.GetHashCode();
        }

        /// <summary>
        /// 获取当前对象于指定对象之间的等价性
        /// </summary>
        /// <param name="obj">指定要比较的对象</param>
        /// <returns>如果两个比较对象等价则返回true，否则返回false</returns>
        public override bool Equals(object obj)
        {
            if(obj is AMLValuePair avp)
            {
                return avp.m_name == this.m_name && avp.m_value == this.m_value;
            }
            return false;
        }

        /// <summary>
        /// 获取当前对象的哈希值
        /// </summary>
        /// <returns>返回当前对象的哈希值</returns>
        public override int GetHashCode()
        {
            return m_name.GetHashCode() ^ m_value.GetHashCode();
        }

        /// <summary>
        /// 获取与当前对象等价的字符串形式
        /// </summary>
        /// <returns>返回与当前对象等价的字符串形式</returns>
        public override string ToString()
        {
            return $"<{m_name},{m_value}>";
        }

        public static bool operator == (AMLValuePair x,AMLValuePair y)
        {
            return x.m_name == y.m_name && x.m_value == y.m_value;
        }

        public static bool operator !=(AMLValuePair x,AMLValuePair y)
        {
            return x.m_name != y.m_name || x.m_value != y.m_value;
        }
    }
}
